﻿using System;
using UnityEngine;

public class Powerup
{
    private object defaultValue;
    public CurrentPowerup powerup;
    private float timer;
    private bool timerActive;

    public Powerup(CurrentPowerup type)
    {
        this.powerup = type;
        this.timer = 0;
        this.timerActive = false;
    }

    public void Update()
    {
        if (this.timerActive)
        {
            this.timer -= Time.deltaTime;
            if (this.timer <= 0)
                Deactivate();
        }
    }

    public void SetType(string newType)
    {
        this.powerup = (CurrentPowerup) Enum.Parse(typeof (CurrentPowerup), newType);
    }

    public void Activate()
    {
        if (!this.timerActive)
        {
            switch (this.powerup)
            {
                case CurrentPowerup.None:
                    this.timer = 0;
                    break;
                case CurrentPowerup.Attack:
                    break;
                case CurrentPowerup.Speed:
                    this.timer = 5000;
                    this.defaultValue = Player.MaxMovementSpeed;
                    Player.MaxMovementSpeed *= 1.25f;
                    break;
                case CurrentPowerup.Defense:
                    break;
                case CurrentPowerup.Immunity:
                    break;
                case CurrentPowerup.WingBoots:
                    break;
                case CurrentPowerup.Food:
                    break;
                case CurrentPowerup.PartyMode:
                    break;
                case CurrentPowerup.FreezeAttack:
                    break;
            }
            this.timerActive = true;
        }
    }

    private void Deactivate()
    {
        switch (this.powerup)
        {
            case CurrentPowerup.None:
                break;
            case CurrentPowerup.Attack:
                break;
            case CurrentPowerup.Speed:
                Player.MaxMovementSpeed = (int) this.defaultValue;
                break;
            case CurrentPowerup.Defense:
                break;
            case CurrentPowerup.Immunity:
                break;
            case CurrentPowerup.WingBoots:
                break;
            case CurrentPowerup.Food:
                break;
            case CurrentPowerup.PartyMode:
                break;
            case CurrentPowerup.FreezeAttack:
                break;
        }

        this.powerup = CurrentPowerup.None;
        this.timer = 0;
        this.timerActive = false;
        this.defaultValue = null;
    }
}